home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9318 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: qiclab.scn.rain.com!qiclab!leonard
  2. From: leonard@qiclab.scn.rain.com (Leonard Erickson)
  3. Newsgroups: comp.lang.c++,comp.os.msdos.programmer
  4. Subject: Re: Timer (0x1C) Interrupt exactly 18.2 seconds?
  5. Date: 29 Feb 1996 14:13:22 -0800
  6. Organization: SCN Research/Qic Laboratories of Tigard, Oregon.
  7. Message-ID: <leonard.825630550@qiclab>
  8. References: <4givrv$cim@midland.co.nz>
  9. Reply-To: shadow@krypton.rain.com
  10. NNTP-Posting-Host: qiclab.scn.rain.com
  11. X-Newsreader: NN version 6.5.0 #3 (NOV)
  12.  
  13. lowefam@igrin.co.nz (Jarrod S Lowe) writes:
  14.  
  15. >I have a C++ Program (on DOS) in which a function is attached to the
  16. >Timer (0x1C) Interrupt.
  17.  
  18. >The function has a static int to count the number of times it has been
  19. >called. Every 'x' calls, It executes another function.
  20.  
  21. >'x' is 546, which one would expect to result in the function being
  22. >called every 30 seconds. However, it is called every 29 point
  23. >something seconds. Over 5 minutes you can see it has drifted. If I had
  24. >one to 'x' (now 547) it is called every 30 point something seconds -
  25. >the same problem in reverse.
  26.  
  27. Take a look at a motherboard. You'll find a crystal marked 14.31818 MHz.
  28. This is used for several things. Divided by 4 it gives the 3.579MHz
  29. "colorburst" frequency needed by CGA cards. Divided by 3 it gives the 4.77
  30. MHz clock used by the original PC & XT. 
  31.  
  32. Now, take that 4.77 MHz (actually 4.772726666... MHz). Divide it by 2^18.
  33. (262,144). That gives you the "clock tick". And as you can see, it *isn't*
  34. 18.2 Hz. It's 18.20650736... Hz. 
  35.  
  36. So I'd advise using (14318180/3) shr 18 instead of 18.2. Or to put it
  37. another way, there are 1,573,042 ticks in a day. And you want your function
  38. called 2880 times in that period. Unfortunately, the *only* common factor
  39. between those numbers is 2. So you'd use 786521/1440 as your counter value.
  40. Messy.
  41.  
  42. If you can afford the RAM, it might be best to just create a table with
  43. 2880 entries, and compare them to the longint clocktick counter in low
  44. RAM. That'd eat up 11 1/4 k of RAM.
  45.  
  46. Otherwise you live with the drift.
  47.  
  48. -- 
  49. Leonard Erickson               leonard@qiclab.scn.rain.com
  50. (aka Shadow)                shadow@krypton.rain.com (preferred)
  51. FIDO:   1:105/51      Leonard.Erickson@f51.n105.z1.fidonet.org 
  52.